package org.rasterfun.language2.bool

import org.rasterfun.language2.Context


/**
 * Provides factory method for creating boolean constants.
 * 
 * @author Hans Haggstrom
 */
object BoolConstant {
  def apply( value : Boolean ) = if (value) True else False

  // TODO: Move to package method in scala 2.8.  Move to some common include object for scala 2.7.
  implicit def boolean2bool(value: Boolean): BoolConstant = BoolConstant.apply(value)
}

/**
 * Boolean constants.
 *
 * @author Hans Haggstrom
 */
sealed abstract case class BoolConstant( value : Boolean ) extends Bool {

  def toBoolean : Boolean = value

//  override def toString = value.toString

  def generateCode(context: Context, s: StringBuilder) {
      s append value
  }

  protected override def alwaysInline = true

}

case object True extends BoolConstant(true)
case object False extends BoolConstant(false)
